﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;

public partial class Factory_Pattern_FeedProxy : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        XNamespace slashNamespace = "http://purl.org/rss/1.0/modules/slash/";
        XDocument rssFeed = XDocument.Load(Request.QueryString["feed"]);

        var posts = from item in rssFeed.Descendants("item")
                    select new
                    {
                        Title = item.Element("title").Value,
                        Published = DateTime.Parse(item.Element("pubDate").Value),
                        Url = item.Element("link").Value,
                        NumComments = item.Element(slashNamespace + "comments").Value
                    };
        Response.Clear();
        Response.ContentType = "application/xml; charset=utf-8";
        Response.Write(rssFeed.ToString());
        Response.End();
    }
}